package com.mytech.cslive;

import com.mytech.cslive.infrastructure.LogFile;

public class Point2D {
	public double x;
	public double y;
	
	public Point2D() {
	}
	
	public Point2D(double x, double y) {
		this.x = x;
		this.y = y;
	}
	
	public Point2D(String x, String y) throws NumberFormatException {
		this.x = Double.parseDouble(x);
		this.y = Double.parseDouble(y);
	}
	
	public void parse(String pointData) throws NumberFormatException {
		try {
			String[] pointAxis = pointData.split(",");
			
			if (pointAxis.length == 2) {
				this.x = Double.parseDouble(pointAxis[0]);
				this.y = Double.parseDouble(pointAxis[1]);
			}
		} catch (NumberFormatException ex) {
			LogFile.log(ex);
			
			throw (ex);
		}
	}
	
    public double distance(Point2D otherPoint) {
        return Math.sqrt(Math.pow((this.x - otherPoint.x), 2)
                + Math.pow((this.y - otherPoint.y), 2));
    }
	  
    public boolean isInRadius(Point2D otherPoint, double radius) {
    	return (this.distance(otherPoint) <= radius);
    }
    
	public String toString() {
		return (this.x + "," + this.y);
	}
}
